package edu.ncu.dao;

import edu.ncu.entity.FriendAsk;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;


import java.util.List;

public interface FriendAskDao {
    @Select("select * from friendAsk where receiverId = #{receiverId} and state = 0;")
    List<FriendAsk> findByUserId(int receiverId);

    @Update("update friendAsk set result = #{result}, state = 1 where receiverId = #{receiverId} and senderId = #{senderId};")
    void update(@Param("result")int result,  @Param("receiverId")int receiverId, @Param("senderId")int senderId);

    @Insert("insert into friendAsk (senderId, receiverId, state) " +
            "values(#{senderId}, #{receiverId}, #{state});")
    void saveFriendAsk(FriendAsk friendAsk);

    @Select("select * from friendAsk where receiverId = #{userId} or senderId=#{userId} ")
    List<FriendAsk> findFriendAsk(int userId);
}
